{% extends 'base.html' %}

{% block css_imports %}
<link
  rel="stylesheet"
  href="https://unpkg.com/@highlightjs/cdn-assets@11.7.0/styles/stackoverflow-dark.min.css" />
<link
  rel="stylesheet"
  href="https://unpkg.com/highlightjs-copy/dist/highlightjs-copy.min.css" />
{% endblock %}

{% block title %}Vertex AI Search Demo - {{title}}{% endblock %}
{% block description %}Select a document from the list to view recommendations of similar documents in the dataset.{% endblock %}

{% block content %}
<form class="search-form" action="/recommend_vais" method="post">
  <!-- Attribution Token -->
  <input type="hidden" name="attribution_token" value="{{ attribution_token }}" />
  <!-- Document Selection Menu -->
  <div class="mdc-select mdc-select--filled document-selection">
    <input type="hidden" name="document_id" />
    <div
      class="mdc-select__anchor"
      role="button"
      aria-haspopup="listbox"
      aria-expanded="false"
      aria-labelledby="document-label document-selected-text">
      <span class="mdc-select__ripple"></span>
      <span id="document-label" class="mdc-floating-label"
        >Get recommendations for a Document</span
      >
      <span class="mdc-select__selected-text-container">
        <span id="document-selected-text" class="mdc-select__selected-text"></span>
      </span>
      <span class="mdc-select__dropdown-icon">
        <svg class="mdc-select__dropdown-icon-graphic" viewBox="7 10 10 5" focusable="false">
          <polygon
            class="mdc-select__dropdown-icon-inactive"
            stroke="none"
            fill-rule="evenodd"
            points="7 10 12 15 17 10"></polygon>
          <polygon
            class="mdc-select__dropdown-icon-active"
            stroke="none"
            fill-rule="evenodd"
            points="7 15 12 10 17 15"></polygon>
        </svg>
      </span>
      <span class="mdc-line-ripple"></span>
    </div>
    <div class="mdc-select__menu mdc-menu mdc-menu-surface mdc-menu-surface--fullwidth">
      <ul class="mdc-list" role="listbox" aria-label="Document picker listbox">
        <li
          class="mdc-list-item mdc-list-item--selected"
          aria-selected="true"
          data-value=""
          role="option">
          <span class="mdc-list-item__ripple"></span>
        </li>
        {% for d in documents %}
        <li
          class="mdc-list-item document-list-item"
          aria-selected="false"
          data-value="{{ d.id }}"
          role="option">
          <span class="mdc-list-item__ripple"></span>
          <span class="mdc-list-item__text"> {{ d.title }} </span>
        </li>
        {% endfor %}
      </ul>
    </div>
  </div>
  <!-- Search Button -->
  <div class="button-container">
    <button
      type="submit"
      class="search-button mdc-button mdc-button--outlined mdc-button--icon-leading">
      <span class="mdc-button__ripple"></span>
      <i class="material-icons mdc-button__icon" aria-hidden="true">search</i>
      <span class="mdc-button__label">Search</span>
    </button>
  </div>
</form>
{% if message_error %}
<div class="mdc-layout-grid">
  <div class="mdc-layout-grid__inner">
    <div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-3"></div>
    <div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-6">
      <pre>{{message_error}}</pre>
    </div>
    <div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-3"></div>
  </div>
</div>
{% elif message_success %}
<div class="mdc-tab-bar" role="tablist">
  <div class="mdc-tab-scroller">
    <div class="mdc-tab-scroller__scroll-area">
      <div class="mdc-tab-scroller__scroll-content">
        <button
          id="entities-tab-selector"
          class="mdc-tab mdc-tab--active"
          role="tab"
          aria-selected="true"
          tabindex="0">
          <span class="mdc-tab__content">
            <span class="mdc-tab__icon material-icons" aria-hidden="true">dataset</span>
            <span class="mdc-tab__text-label">Results</span>
          </span>
          <span class="mdc-tab-indicator mdc-tab-indicator--active">
            <span
              class="mdc-tab-indicator__content mdc-tab-indicator__content--underline"></span>
          </span>
          <span class="mdc-tab__ripple"></span>
        </button>
        <button id="json-tab-selector" class="mdc-tab mdc-tab" role="tab" tabindex="1">
          <span class="mdc-tab__content">
            <span class="mdc-tab__icon material-icons" aria-hidden="true">code</span>
            <span class="mdc-tab__text-label">JSON</span>
          </span>
          <span class="mdc-tab-indicator">
            <span
              class="mdc-tab-indicator__content mdc-tab-indicator__content--underline"></span>
          </span>
          <span class="mdc-tab__ripple"></span>
        </button>
      </div>
    </div>
  </div>
</div>
<div class="tab-content">
  <div id="entities-tab" class="tab-visible">
    {% if results|length == 0 %}
    <p class="empty-results-message">No recommendations were found for this document.</p>
    {% endif %} {% for result in results %}
    <div class="mdc-layout-grid">
      <div class="mdc-layout-grid__inner">
        <div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-6">
          <div class="mdc-card mdc-card--outlined">
            <div class="mdc-card__primary-action entity-primary-action" tabindex="0">
              <div class="entity-card-primary">
                {% set resultUrl = result["link"] %}
                <a href="{{resultUrl}}" target="_blank" rel="noopener noreferrer">
                  <h2 class="mdc-typography mdc-typography--headline6">
                    {{result["title"]|safe}}
                  </h2>
                </a>
                <h3 class="mdc-typography mdc-typography--subtitle2">
                  Document ID: <code>{{result["id"]|safe}}</code>
                </h3>
                <h3 class="mdc-typography mdc-typography--subtitle2">
                  MIME Type: <code>{{result["mimeType"]|safe}}</code>
                </h3>
              </div>
            </div>
          </div>
        </div>
        <div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-6">
          <div class="mdc-card mdc-card--outlined">
            <pre><code class="language-json" lang="json">{{result["resultJson"]}}</code></pre>
          </div>
        </div>
      </div>
    </div>
    {% endfor %}
  </div>
  <div id="json-tab" class="tab-hidden">
    {% if request_url %}
    <div class="mdc-layout-grid">
      <div class="mdc-layout-grid__inner">
        <div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-2"></div>
        <div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-8">
          <b>Request URL:</b>
          <pre><code class="language-shell" lang="shell">{{request_url}}</code></pre>
        </div>
        <div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-2"></div>
      </div>
    </div>
    {% endif %}
    <div class="mdc-layout-grid">
      <div class="mdc-layout-grid__inner">
        {% if raw_request %}
        <div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-6">
          <b>Request Body:</b>
          <pre><code class="language-json" lang="json">{{raw_request}}</code></pre>
        </div>
        {% endif %} {% if raw_response %}
        <div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-6">
          <b>Response Body:</b>
          <pre><code class="language-json" lang="json">{{raw_response}}</code></pre>
        </div>
        {% endif %}
      </div>
    </div>
  </div>
</div>
{% endif %}
{% endblock %}

{% block footer %}
Made by <a href="https://github.com/holtskinner">holtskinner@</a> - Powered by
<a href="https://cloud.google.com/generative-ai-app-builder/docs/try-personalize">Personalize</a>
with <a href="https://cloud.google.com/generative-ai-app-builder">Vertex AI Search</a>
on <a href="https://cloud.google.com/">Google Cloud</a>
{% endblock %}

{% block js_imports %}
<script src="https://unpkg.com/@highlightjs/cdn-assets@11.7.0/highlight.min.js"></script>
<script src="https://unpkg.com/highlightjs-copy/dist/highlightjs-copy.min.js"></script>
<script src="{{url_for('static', filename='recommend.js')}}"></script>
{% endblock %}
